import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LC228
 * @Author ykx
 * @Date 2024/7/8 22:15
 * @Version 1.0
 */
public class LC228 {
    public static void main(String[] args) {
        LC228 lc228 = new LC228();
        System.out.println(lc228.summaryRanges(new int[]{0, 1, 2, 4, 5, 7}));
    }

    public List<String> summaryRanges(int[] nums) {
        List<String> result = new ArrayList<>();
        if (nums.length == 1) {
            result.add(nums[0] + "");
            return result;
        } else if (nums.length == 0) {
            return result;
        }

        int from = nums[0], to = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] - nums[i - 1] == 1) {
                to++;
            } else {
                result.add(from == to ? from + "" : from + "->" + to);
                from = nums[i];
                to = nums[i];
            }

            if (i == nums.length - 1) {
                result.add(from == to ? from + "" : from + "->" + to);
            }

        }
        return result;
    }

}
